<div class="layui-row">
    <div class="layui-card-header">
        <div class="left tbt">
            共{$lists->total()}条记录  <span class="x-red" id="onsel" style="display: none;">已选择<span id="onselnum"></span>条</span>
        </div>
        {if !$isearch}
        <div class="right">
            <button class="layui-btn layui-btn-primary addline" onclick="addline()">新增条目</button>
            <button class="layui-btn layui-btn-primary selobj" onclick="sel()" data-type="sel">批量选择</button>
            <button class="layui-btn layui-btn-danger del" onclick="del()">删除</button>
        </div>
        {else}
        <div class="right">
            <form action="{:url('cartoon/details')}" id="search" method="get" class="layui-form layui-col-space5 hide">
                <input type="hidden" name="search" value="1">
                <input type="hidden" name="id" value="{$item.id}">
                <input type="hidden" name="sel" value="{$sel}">
                <input type="hidden" name="year">
                <input type="hidden" name="staff">
                <div class="layui-inline layui-show-xs-block">
                    <select name="search_type" lay-filter="search_type">
                        <option value="">筛选条件</option>
                        <option value="year" {if request()->get('search_type') eq 'year'}selected{/if}>按年份</option>
                        <option value="cat1" {if request()->get('search_type') eq 'cat1'}selected{/if}>只看剧场版</option>
                        <option value="cat2" {if request()->get('search_type') eq 'cat2'}selected{/if}>只看特别版</option>
                        <option value="tdcyr" {if request()->get('search_type') eq 'tdcyr'}selected{/if}>按特定参与人</option>
                    </select>
                </div>
            </form>
        </div>
        {/if}
    </div>
    <div class="layui-card-body layui-card-body-table">
        <table class="layui-table layui-form">
            <thead>
            <tr>
                {if !$isearch}
                <th rowspan="2"></th>
                {/if}
                <th rowspan="2">首更日期</th>
                <th rowspan="2">星期</th>
                <th rowspan="2">编号</th>
                <th rowspan="2">发行公司</th>
                <th rowspan="2">标题（中）</th>
                <th rowspan="2">标题（日）</th>
                <th rowspan="2">时长</th>
                <th colspan="2">主题曲</th>
                <th colspan="15">制作人员</th>
                <th rowspan="2">声优</th>
            </tr>
            <tr>
                <th>曲名</th>
                <th>歌手</th>
                <th>
                    <p class="zh">原作</p>
                    <p class="jp">原作</p>
                </th>
                <th>
                    <p class="zh">导演</p>
                    <p class="jp">監督</p>
                </th>
                <th>
                    <p class="zh">编剧</p>
                    <p class="jp">脚本</p>
                </th>
                <th>
                    <p class="zh">音乐</p>
                    <p class="jp">音楽</p>
                </th>
                <th>
                    <p class="zh">分镜</p>
                    <p class="jp">絵コンテ</p>
                </th>
                <th>
                    <p class="zh">分镜协力</p>
                    <p class="jp">絵コンテ協力</p>
                </th>
                <th>
                    <p class="zh">演出</p>
                    <p class="jp">演出</p>
                </th>
                <th>
                    <p class="zh">作画导演</p>
                    <p class="jp">作画監督</p>
                </th>
                <th>
                    <p class="zh">作画导演助理</p>
                    <p class="jp">作画監督補佐</p>
                </th>

                <th>
                    <p class="zh">总作画导演</p>
                    <p class="jp">總作作画監督</p>
                </th>
                <th>
                    <p class="zh">动作作画导演</p>
                    <p class="jp">アクション作画監督</p>
                </th>
                <th>
                    <p class="zh">角色设计</p>
                    <p class="jp">キャラクターデザイン</p>
                </th>
                <th>
                    <p class="zh">色彩设计</p>
                    <p class="jp">色彩設計</p>
                </th>
                <th>
                    <p class="zh">色指定</p>
                    <p class="jp">色指定</p>
                </th>
                <th>
                    <p class="zh">原画</p>
                    <p class="jp">原画</p>
                </th>
            </tr>
            </thead>
            <tbody id="moviebody">
            {php}
            $datas = $lists->toArray()["data"];
            {/php}
            {volist name="$datas" id="item"}
            {php}
            $redcolor = false;
            if($item["add_time"]){
            $theyear = date("Y",$item["add_time"]);
            $nextdata = isset($datas[$key+1])?$datas[$key+1]:null;
            if($nextdata){
            $nextyear =date("Y",$nextdata["add_time"]);
            if($theyear!=$nextyear){
            $redcolor = true;
            }
            }
            }
            {/php}
            <tr class="tr_{$item.id} {if $redcolor} redcolor {/if} {if $item.display eq 0} dls{/if}">
                {if !$isearch}
                <td>
                    <a href="javascript:;" class="editbtn" onclick="xadmin.open(null,'{:url("ova/post")}?id={$item.id}')">编辑</a>
                    <div style="display: none;" class="selone"><input type="checkbox" name="selone" value="{$item.id}" lay-filter="selone" lay-skin="primary" ></div>
                </td>
                {/if}
                <td class="btr">
                    {if $item.add_time}
                    {:date("Y年n月j日",$item['add_time'])}
                    {else}
                    /
                    {/if}
                </td>
                <td>
                    {if $item.add_time}
                    周{:formatWeek(date('w',$item['add_time']))}
                    {/if}
                </td>

                <td>
                    {if $item.cat}
                    {if $item.cat eq 1}
                    M
                    {else}
                    特
                    {/if}
                    {/if}
                    {$item.words1}
                </td>
                <td>{$item.publisher}</td>
                <td>{$item.title}</td>
                <td>{$item.title_jp}</td>
                <td>{if $item.time_lenth}{$item.time_lenth}分钟{/if}</td>
                <td>{$item.song_title}</td>
                <td>{$item.song_man}</td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][1] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][2] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][3] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][4] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][5] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][6] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][7] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][8] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][9] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][10] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][11] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][12] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][13] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][14] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    {if count($item['staff'])>=1}
                    {foreach $item['staff'][15] as $v}
                    <span class="zh">{$v.username}</span> <span class="jp">{$v.username_jp}</span> <br>
                    {/foreach}
                    {/if}
                </td>
                <td>
                    <a href="javascript:;" onclick="xadmin.open('声优查看','{:url("ova/seiyuu",["id"=>$item['id']])}')">点击查看</a>
                </td>
            </tr>
            {/volist}

            </tbody>
        </table>
    </div>
    <div class="layui-card-body ">
        {$lists|raw}
    </div>

</div>
<script>
    function del() {
        var id;
        let seltype = $('.selobj').data("type")
        if(seltype==="sel"){
            id = [$('[name="selone"]').last().val()]
        }else{
            id = getselall()
        }

        layer.confirm("{:lang('del.confirm')}",{icon: 3, title:'{:lang("tips")}'},function (index) {
            layer.close(index);
            request("POST",'{:url("ova/del")}',{
                id:id
            },function (res) {
                window.location.reload()
            })

        })
    }
    function addline() {
        request("POST",'{:url("ova/add")}',{work_id:id},function (res,msg) {
            var html
            html +=`<tr class="tr_${res.id}">`
            html +='<td>'
            html +=`<a href="javascript:;" class="editbtn" onclick="xadmin.open('{$item.title}','{:url("movie/post")}?id=${res.id}')">编辑</a>`
            html +=`<div style="display: none;" class="selone"><input type="checkbox" name="selone" value="${res.id}" lay-skin="primary" /></div>`
            html +='</td>';
            for(var i = 1;i<=24;i++){
                if(i==3){
                    html +=`<td>${res.words1}</td>`
                }else{
                    html +=`<td>/</td>`
                }
            }
            html +=`</tr>`
            window.location.reload();

            // $('#moviebody').append(html)

        })
    }

</script>